﻿using System;
using System.Web;
using System.Web.UI;
using System.Linq;
using Models;


public partial class TagAdd : AdminBase
{
    public int _Id = 0;
    public string _type = "";

    protected void Page_Load(object sender, EventArgs e)
    {

        Response.CacheControl = "no-cache";
        if (!string.IsNullOrEmpty(Request.Params["ID"]))
        {
            _Id = int.Parse(HttpContext.Current.Request.QueryString["ID"]);
        }

        if (!string.IsNullOrEmpty(Request.Params["type"]))
        {
            _type = HttpContext.Current.Request.QueryString["type"];
        }

        if (!Page.IsPostBack)
        {

            if (_Id != 0)
            {
                ShowInfo(_Id);
            }
        }
    }

    private void ShowInfo(int _id)
    {

        Entities mydb = new Entities();
        {
            S_Store _ls = mydb.S_Store.FirstOrDefault(p => p.SID == _id);
            txtTel.Text = methods.getUser(_ls.OpenId)[0] + methods.getUser(_ls.OpenId)[1];
            txtUGuid.Text = _ls.OpenId;
        }
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        Entities mydb = new Entities();
        {
            S_Store Lt = new S_Store();
            if (_Id != 0)
                Lt = mydb.S_Store.First(p => p.SID == _Id);
            Lt.OpenId = txtParentUGuid.Text.Trim();


            if (_Id == 0)
            {
                mydb.S_Store.Add(Lt);
                mydb.SaveChanges();
                Response.Write("<script> var Close=1;</script>");
            }
            else
            {
                mydb.SaveChanges();
                Response.Write("<script> var Close=1;</script>");
            }
        }
    }
}

